<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="编辑" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>

<script setup lang="ts">
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';
  import { schemas } from './edit.data';
  import { otaPackageInfo } from '/@/api/thingsborad/advanced/OTA/OTA';
  import { onMounted, ref } from 'vue';
  import { modalFormStyleSetting, modalStyleSetting } from '/@/settings/thingsBoardDesign';
  const emit = defineEmits(['success']);

  const response = ref<any>();
  const [registerForm, { setFieldsValue, getFieldsValue }] = useForm({
    showActionButtonGroup: false,
    layout: 'vertical',
    schemas,
    ...modalFormStyleSetting,
  });
  const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
    response.value = await otaPackageInfo(data.record.otaPackageId);
    setFieldsValue({ remark: response.value.additionalInfo.description });
  });

  const handleSubmit = async () => {
    try {
      const values = getFieldsValue();
      emit('success', { key: 'edit', values: { values, record: response.value } });
      closeModal();
    } catch (error) {
      
    }
  };
  onMounted(() => setModalProps({ ...modalStyleSetting }));
</script>
